<HTML><HEAD><TITLE>set_stream(+StreamId, +Stream)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Stream I/O</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>set_stream(+StreamId, +Stream)</H1>
The symbolic stream name StreamId is associated with the stream Stream.


<DL>
<DT><EM>StreamId</EM></DT>
<DD>Atom.
</DD>
<DT><EM>Stream</EM></DT>
<DD>Integer (stream number) or Atom (reserved or user-defined symbolic stream name).
</DD>
</DL>
<H2>Description</H2>
   This predicate is used to create new symbolic alias names for physical
   streams, or to redirect existing symbolic stream names to other physical
   streams.
<P>
   If StreamId is a new user-defined stream name, then that new name is
   associated with the physical stream denoted by the Stream.  Stream can be
   in the form of a physical stream number, a name of a physical stream
   (stdin, stdout, stderr, null), or any existing symbolic stream name.
<P>
   If StreamId is an already existing stream name (including one of the
   symbolic system stream names like input, output, error, warning_output,
   log_output), then that stream is redirected to Stream. Any previously
   existing association of the name StreamId is forgotten. Note that other
   alias names for the same physical stream are not affected by redirection.
<P>
   When a user-defined symbolic stream is closed, the associated physical
   stream is closed and the association forgotten.
   Note that it is not enough to close the physical stream alone because
   the association of symbolic an physical stream remains (even though the
   physical stream is closed) until the symbolic stream is closed as well.
   A system-defined symbolic stream will be redirected to its default when
   the associated physical stream is closed.
<P>
   The physical stream associated with a symbolic stream name can be
   queried using get_stream/2.
<P>

<H3>Modes and Determinism</H3><UL>
<LI>set_stream(+, +) is det
</UL>
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Either StreamId or Stream is uninstantiated.
<DT><EM>(5) type error </EM>
<DD>Either StreamId is not an atom or Stream is not a stream    number or symbolic stream name.
<DT><EM>(193) illegal stream specification </EM>
<DD>Stream is an illegal stream specification.
<DT><EM>(194) too many symbolic names of a stream </EM>
<DD>A physical stream has more than 255 logical stream names    assigned to it.
</DL>
<H2>Examples</H2>
<PRE>
        % suppress standard output temporarily:
	[eclipse]: set_stream(output, null).
	Yes (0.00s cpu)
	[eclipse]: writeln(hello).
	Yes (0.00s cpu)

        % set standard output back to default:
	[eclipse]: set_stream(output, stdout).
	Yes (0.00s cpu)
	[eclipse]: writeln(hello).
	hello
	Yes (0.00s cpu)

        % alias the names s and output:
        [eclipse]: open(file1,update,s), set_stream(output,s),
		   writeln(output,hi), flush(output).
	yes.
	[eclipse]: seek(s,0), read(s,X).
	X = hi
	yes.

Error:
        set_stream(a, S).        (Error 4).
        set_stream(1.0, S).      (Error 5).
        set_stream(a, nonex).    (Error 193).
</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/iostream/open-4.html">open / 4</A>, <A HREF="../../kernel/iostream/get_stream-2.html">get_stream / 2</A>
</BODY></HTML>
